var prefix = api + "/admin/social";
var oper = getQueryString('oper')
var id = getQueryString('id')

$(function () {

  renderDictFilter('#type', 'social_type')
  $('#oper').val(oper)
  if (oper === 'edit' || oper === 'view') {
    socialDetail(id)
  }
  $.common.initFormInfo();
});

function socialDetail(id) {
  $.operate.get(api + '/admin/social/id/' + id, function (res) {
    res.data[0].oper = oper
    applyDrawing('#editForm', res.data[0])
    if (!$('#type').val() && res.data[0].type){
      $('#type').append('<option style="display:none" value="' + res.data[0].type + '">' + res.data[0].type + '</option>')
      $('#type').val(res.data[0].type)
    }

  }, false)
}

$("#editForm").validate({
  onkeyup: false,
  rules: {
    socialTypeFlag: {
      required: true,
    },
    appId: {
      required: true
    },
    appSecret: {
      required: true,
    },
    redirectUrl: {
      required: true
    }
  },
  focusCleanup: true
});


function submitHandler() {
  if ($.validate.form()) {
    $.common.ajaxCommitForm($('#editForm'), false);
    return false;
  }
}